package frontend.pages.admin.department;

import backend.model.admin.Department;
import backend.service.admin.DepartmentService;
import frontend.core.TimeTrackingWebApplication;
import frontend.model.admin.DepartmentUIModel;
import frontend.pages.admin.base.AbstractManagingPage;
import org.apache.wicket.markup.html.panel.Panel;
import org.wicketstuff.annotation.mount.MountPath;

import java.util.List;

@MountPath("department")
public class DepartmentManagingPage extends AbstractManagingPage<Department> {

    public DepartmentManagingPage() {
        super("pages.admin.department.title", "contextualHelp.admin.department.text");
    }

    @Override
    protected String getAddPanelTitleKey() {
        return "pages.admin.department.add.title";
    }

    @Override
    protected String getEditPanelTitleKey() {
        return "pages.admin.department.edit.title";
    }

    @Override
    protected String getNoSelectionMessageKey() {
        return "pages.admin.department.edit.noSelection";
    }

    @Override
    protected Panel getAddPanel(String panelId) {
        return new DepartmentPanel(panelId, getPageParameters(), new DepartmentUIModel());
    }

    @Override
    protected Panel getEditPanel(String panelId, Department department) {
        getPageParameters().clearNamed();
        return new DepartmentPanel(panelId, null, new DepartmentUIModel(department));
    }

    @Override
    public List<Department> loadAvailableEntities() {
        DepartmentService departmentService = TimeTrackingWebApplication.getService(DepartmentService.class);
        return departmentService.findAllDepartments();
    }
}
